package com.smasher.update.component.update

import android.content.Context
import com.smasher.update.component.check.CheckDelegate
import com.smasher.update.component.check.CheckInfoImplSoftOut
import com.smasher.update.component.download.DownloadDelegate
import com.smasher.update.component.download.DownloadFinishListener
import com.smasher.update.component.download.sys.DownloadImplSystem
import com.smasher.update.component.parse.OnParseListener
import com.smasher.update.component.parse.ParseDelegate
import com.smasher.update.component.parse.ParseImplSoftOut

/**
 * 检查代理构建器
 */

class ExecutorBuilder(context: Context) {

    private var checkDelegate: CheckDelegate = CheckInfoImplSoftOut(context)
    private var parseDelegate: ParseDelegate = ParseImplSoftOut()
    private var downloadExecutor: DownloadDelegate = DownloadImplSystem(context)
    private var downloadFinishListener: DownloadFinishListener? = null
    private var parseListener: OnParseListener? = null

    fun initVersionCheckDelegate(delegate: CheckDelegate): ExecutorBuilder {
        this.checkDelegate = delegate
        return this
    }

    fun initParseDelegate(delegate: ParseDelegate): ExecutorBuilder {
        this.parseDelegate = delegate
        return this
    }

    fun initDownloadDelegate(downloadExecutor: DownloadDelegate): ExecutorBuilder {
        this.downloadExecutor = downloadExecutor
        return this
    }

    fun setDownloadFinishListener(downloadFinishListener: DownloadFinishListener): ExecutorBuilder {
        this.downloadFinishListener = downloadFinishListener
        return this
    }

    fun setParseListener(parseListener: OnParseListener): ExecutorBuilder {
        this.parseListener = parseListener
        return this
    }

    fun create(): UpdateExecutor {
        return UpdateExecutor(
            checkDelegate,
            parseDelegate,
            downloadExecutor,
            parseListener,
            downloadFinishListener
        )
    }
}